package cn.maszy.service.impl.investment;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.maszy.common.DateUtils;
import cn.maszy.common.Pager;
import cn.maszy.common.SessionFactory;
import cn.maszy.dao.investment.B_T_Ufp_LeaveMapper;
import cn.maszy.model.investment.B_T_Ufp_Leave;
import cn.maszy.model.investment.B_T_Ufp_LeaveExample;
import cn.maszy.model.investment.B_T_Ufp_LeaveExample.Criteria;
import cn.maszy.service.investment.B_T_Ufp_LeaveService;


@Service
public class B_T_Ufp_LeaveServiceImpl implements B_T_Ufp_LeaveService{
	@Autowired
	private B_T_Ufp_LeaveMapper b_T_Ufp_LeaveMapper;
	
	
	
	
	
	public int update(B_T_Ufp_Leave b_T_Ufp_Leave) {
		// TODO Auto-generated method stub
		 if(b_T_Ufp_Leave.getUuid()==null||"".equals(b_T_Ufp_Leave.getUuid())){
			 b_T_Ufp_Leave.setUuid(UUID.randomUUID().toString());
			 b_T_Ufp_Leave.setIsDelete(0);
			 b_T_Ufp_Leave.setCreateTime(new Date());
			 b_T_Ufp_Leave.setCreateUser(SessionFactory.getSessionUserRealNam());
			 return b_T_Ufp_LeaveMapper.insert(b_T_Ufp_Leave);
		 }else{
			 b_T_Ufp_Leave.setUpdateTime(new Date());
			 b_T_Ufp_Leave.setUpdateUser(SessionFactory.getSessionUserRealNam());
			 return b_T_Ufp_LeaveMapper.updateByPrimaryKeySelective(b_T_Ufp_Leave);
		 }
	}

	public B_T_Ufp_Leave selectOne(String uuid) {
		B_T_Ufp_Leave record=b_T_Ufp_LeaveMapper.selectByPrimaryKey(uuid);
		return record;
	}

	public int delete(String checkIds) {
		// TODO Auto-generated method stub
		for (String id : checkIds.split(", ")) {
			b_T_Ufp_LeaveMapper.deleteByPrimaryKey(id);
		}
		return 1;
	}

	public int count(B_T_Ufp_LeaveExample example,B_T_Ufp_LeaveMapper b_T_Ufp_LeaveMapper) {
		return b_T_Ufp_LeaveMapper.countByExample(example);
	}

	public Pager<B_T_Ufp_Leave> selectList(B_T_Ufp_Leave b_T_Ufp_Leave,Pager<B_T_Ufp_Leave> pager) {
		B_T_Ufp_LeaveExample example=new B_T_Ufp_LeaveExample();
		Criteria criteria = example.createCriteria();
		if(b_T_Ufp_Leave!=null){
			if(b_T_Ufp_Leave.getLeavename()!=null&&!"".equals(b_T_Ufp_Leave.getLeavename())){
					criteria.andLeavenameLike("%"+b_T_Ufp_Leave.getLeavename()+"%");
				}
			if(b_T_Ufp_Leave.getDepname()!=null&&!"".equals(b_T_Ufp_Leave.getDepname())){
					criteria.andDepnameLike("%"+b_T_Ufp_Leave.getDepname()+"%");
				}
			if(b_T_Ufp_Leave.getLeavetime()!=null&&!"".equals(b_T_Ufp_Leave.getLeavetime())){
					criteria.andLeavetimeLike("%"+b_T_Ufp_Leave.getLeavetime()+"%");
				}
		}else{
			criteria.andUuidIsNotNull();
		}
		example.or(criteria);
		int totalCount=new B_T_Ufp_LeaveServiceImpl().count(example,b_T_Ufp_LeaveMapper);
		pager.setTotalRecords(totalCount);
		example.setLimitStart(pager.getStartRecord());
		example.setLimitEnd(pager.getPageSize());
		example.setOrderByClause(pager.getOrderField()+" "+pager.getOrderDirection());
		
		// 取得总的记录条数
		List<B_T_Ufp_Leave>  list=b_T_Ufp_LeaveMapper.selectByExample(example);
		pager.setPageRecords(list);
		return pager;
	}
}
